package src.main.java.org.io;

import java.io.*;

/*
* try-catch-finally
* */
public class Test5 {
    public static void main(String[] args) {
        InputStream fis = null;
        OutputStream fos = null;
        try {
            fis = new FileInputStream("E:\\ab.txt");
            fos = new FileOutputStream("D:\\ab.txt");

            byte[] buffer = new byte[1024];//创建一个字符数组，负责转移数据
            int len;
            while((len= fis.read(buffer))!=-1){
                fos.write(buffer,0,len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            //释放资源
            try {
                if(fos!=null) fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            try {
                if(fis!=null) fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
